<?php

namespace app\api\controller;

use app\service\plc\PlcAccess;

class PlcController
{

    public function index()
    {
        try {
            $plc = PlcAccess::create("s7", "192.168.110.68:102");
            $plc->write([
                ["DB1.0:int32", 24],
                ["DB1.4:float", 3.14],
                ["DB1.12.1:bit", 9]
            ]);
            $res = $plc->read(["DB1.0:int32", "DB1.4:float", "DB1.12.1:bit"]);
            return successMessage("操作成功",$res);
        }
        catch (\Exception $ex) {
            return errorMessage($ex->getMessage());
        }

    }
}
